//
//  TempViewController.swift
//  WeiboProject
//
//  Created by amos on 16/1/18.
//  Copyright © 2016年 itheima. All rights reserved.
//

import UIKit

class TempViewController: UIViewController {


    override func viewDidLoad() {
        //1.设置 title
        navigationItem.title = "第\((navigationController?.childViewControllers.count)! - 1)个控制器"
        
        
        var title = "返回"
        //如果为1
        
        print("\(navigationController?.childViewControllers.first?.navigationItem.title)")
        if navigationController?.childViewControllers.count == 2{
            title = (navigationController?.childViewControllers.first?.navigationItem.title) ?? ""
            
        }
        
        //1.设置左边 button
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: title ,imageName: "navigationbar_back_withtext", target: self, action: "popBack")
        
        //2.设置右边 button
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "PUSH", target: self, action: "push")
        
        //3.设置颜色
        view.backgroundColor = UIColor.whiteColor()
        
        hidesBottomBarWhenPushed = true
    }
    
    @objc private func popBack(){
        
        navigationController?.popViewControllerAnimated(true)
        
        print("返回")
    }
    
    @objc private func push(){
        navigationController?.pushViewController(TempViewController(), animated: true)
    }
}
